﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace Xid.Controls.IsaExport
{
    static class Extentions
    {
        // http://stackoverflow.com/questions/1799370/getting-attributes-of-enums-value
        public static string GetDescription(this Enum enumValue)
        {
            DescriptionAttribute attribute = null;
            try {
                attribute = enumValue.GetType().GetMember(enumValue.ToString())[0].GetCustomAttributes(typeof(DescriptionAttribute), false).Cast<DescriptionAttribute>().SingleOrDefault();
            }
            catch (Exception e) { }

            return attribute == null ? String.Empty : attribute.Description;
        }

        public static List<String> GetFilesRecursively(this String startDir)
        {
            List<String> rs = Directory.GetFiles(startDir).ToList<String>();
            foreach (String d in Directory.GetDirectories(startDir))
            {
                rs.AddRange(GetFilesRecursively(d));
            }
            return rs;
        }


        public static List<T> Clone<T>(this List<T> listToClone) where T : ICloneable
        {
    		return listToClone.Select(item => (T)item.Clone()).ToList();
    	}
    }
}
